<?php
/*
 * Created on 08/07/2009
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
include("Course.php");

$archivo = '../../data.xml';

$curso = new Course();




if (file_exists($archivo)) {
  $xml = simplexml_load_file($archivo); 
  
  if($xml){
    foreach ($xml->xpath('//chapter') as $xmlelement) {
      $capCur=new Chapter($xmlelement['id'],$xmlelement['title']);
      $curso->addChapter($capCur);
    }
    
    foreach($curso->getChapters() as $chapts){
    	echo $chapts->getId()."<br>";
    	echo $chapts->getTitle()."<br><br>";
    }
    
    foreach ($xml->xpath('//relationship') as $xmlelement) {
    	$topc = new Topic($xmlelement['son']);
    	$chapt=$curso->getChapter($xmlelement['father']);
    	
    	if($chapt != null)
    		$chapt->addTopic($topc);	
    }
    
    foreach ($xml->xpath('//topic') as $xmlelement) {
    	foreach($curso->getChapters() as $chapts){
    		if( $chapts->getTopic($xmlelement['id'])!=null){
    			$topc=$chapts->getTopic($xmlelement['id']);
    			$topc->setTitle($xmlelement['title']);
    			$topc->setTitle($xmlelement['title']);
    			
    			break;
    		}
    	}
    }
    
    
  } else echo "Sintaxi XML inválida";
} else echo "Error abriendo Curso";  

?>



